コード

  1. import japanize_kivy
  2. import urllib.parse
  3. import kivy
  4. from kivy.app import App
  5. from kivy.uix.boxlayout import BoxLayout
  6. from kivy.uix.textinput import TextInput
  7. from kivy.uix.button import Button
  8. import webbrowser
  9. kivy.require('1.11.1')
  10. class HashTagSearchApp(App):
  11.     def __init__(self, **kwargs):
  12.         super().__init__(**kwargs)
  13.         self.links = []
  14.     def build(self):
  15.         self.layout = BoxLayout(orientation='vertical')
  16.         self.input_text = TextInput(hint_text='enter a hashtag without "#"')
  17.         self.add_button = Button(text='search')
  18.         self.add_button.bind(on_press=self.search_hashtag)
  19.         self.layout.add_widget(self.input_text)
  20.         self.layout.add_widget(self.add_button)
  21.         return self.layout
  22.     def search_hashtag(self, instance):
  23.         hashtag = self.input_text.text.strip()
  24.         if hashtag:
  25.             hashtag = urllib.parse.quote(hashtag) # キーワードをエンコード
  26.             search_url = f'https://bizwd.net/'
  27.             webbrowser.open(search_url)
  28. if __name__ == '__main__':
  29.     HashTagSearchApp().run()